package com.ruoyi.exportCustomer.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.customer.domain.bo.ExportInfoBo;
import com.ruoyi.exportCustomer.domain.LogsInfo;
import com.ruoyi.exportCustomer.domain.bo.ExportLogBo;
import com.ruoyi.exportCustomer.domain.vo.ExportLogVo;
import com.ruoyi.exportCustomer.service.IExportLogService;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 导入记录
 *
 * @author ruoyi
 * @date 2023-08-23
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/exportLog")
public class ExportLogController extends BaseController {

    private final IExportLogService iExportLogService;

    /**
     * 查询导入记录列表
     */
    @SaCheckPermission("log:exportLog:list")
    @GetMapping("/list")
    public TableDataInfo<ExportLogVo> list(ExportLogBo bo, PageQuery pageQuery) {
        return iExportLogService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询导入记录列表
     */
    @GetMapping("/logList")
    public TableDataInfo<LogsInfo> logList(LogsInfo bo, PageQuery pageQuery) {
        return iExportLogService.queryPageList(bo, pageQuery);
    }


    @PostMapping("/oneKeyIssueToDept")
    public R oneKeyIssueToDept(@RequestBody ExportInfoBo issueBo) {
        return iExportLogService.oneKeyIssueToDept(issueBo);
    }

    @PostMapping("/oneKeyIssueToUser")
    public R oneKeyIssueToUser(@RequestBody ExportInfoBo issueBo) {
        return iExportLogService.oneKeyIssueToUser(issueBo);
    }

    /**
     * 导出导入记录列表
     */
    @SaCheckPermission("log:exportLog:export")
    @Log(title = "导入记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ExportLogBo bo, HttpServletResponse response) {
        List<ExportLogVo> list = iExportLogService.queryList(bo);
        ExcelUtil.exportExcel(list, "导入记录", ExportLogVo.class, response);
    }


    /**
     * 新增导入记录
     */
    @SaCheckPermission("log:exportLog:add")
    @Log(title = "导入记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("importData")
    public R importData(@RequestPart("file") MultipartFile file, String batchLog) {
        return iExportLogService.importData(file, batchLog);
    }


}
